package com.mse.web.biz;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mse.model.biz.Member;
import com.mse.service.biz.MemberService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import top.ibase4j.core.base.BaseController;
import top.ibase4j.core.util.WebUtil;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author ShenHuaJie
 * @since 2019-04-05
 */
@RestController
@RequestMapping("/member")
@Api(value = "接口", description = "接口")
public class MemberController extends BaseController<Member, MemberService> {
    @PostMapping(value = "/read/list")
    @ApiOperation(value = "查询全部", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object query(HttpServletRequest request) {
        Map<String, Object> param = WebUtil.getParameter(request);
        return super.queryList(param);
    }

    @PostMapping(value = "/read/page")
    @ApiOperation(value = "分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object queryPage(HttpServletRequest request) {
        Map<String, Object> param = WebUtil.getParameter(request);
        return super.query(param);
    }

    @GetMapping(value = "/read/detail")
    @ApiOperation(value = "详情", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object get(HttpServletRequest request) {
        Member param = WebUtil.getParameter(request, Member.class);
        return super.get(param);
    }

    @GetMapping(value = "/read/one")
    @ApiOperation(value = "详情", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object selectOne(HttpServletRequest request) {
        Member param = WebUtil.getParameter(request, Member.class);
        Member result = service.selectOne(param);
        return setSuccessModelMap(result);
    }

    @PostMapping
    @ApiOperation(value = "修改", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object update(HttpServletRequest request, Member param) {
        return super.update(param);
    }

    @DeleteMapping
    @RequiresPermissions("member.delete")
    @ApiOperation(value = "删除", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object del(HttpServletRequest request) {
        Member param = WebUtil.getParameter(request, Member.class);
        return super.delete(param);
    }
}